<!DOCTYPE html>
<?php
Session_start();
$member_id = $_SESSION['member_id'];
$conference_id = intval($_GET['conference_id']);
?>
<html>
    <head>
        <?php
        include "jquery.php"
        //the javescript function that displays the calendar
        ?>
        <script type="text/javascript" src="calendar.js"></script>
        <script type="text/javascript">
            function init() {
                calendar.set("dd");
            }
        </script>
            
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Post News</title>
            
    </head>
    <body>
<? // creating the header , the textFields and the buttons   ?>
        <h2>Post News</h2>
        <form method="post" Action ="" >

            <p><strong>Title</strong><br>
    
                <input type ="text" name ="ti" maxlength ="50"/>
     
            </p>
    
            <p><strong>News:</strong></p>
    
            <p>
    
                <textarea name="news" cols="75" rows="10"></textarea>

            </p>
            <p><strong>  Expiry date: </strong></p>
      
            <input id="dd" type="text" name="date" maxlength="10" size="15"  readonly = "readonly" onfocus="javascript: init();"></input>
        </p>
        <p>
    
            <input name="submit" type="submit" value="Post">
            <input name="clear" type="reset" value="Clear">
        
    </form>
</body>
</html>
<?
//check if the user clicked on submit button 
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// store the textFields values in 3 variables
    $title = $_POST['ti'];
    $news = $_POST['news'];
    $date = $_POST['date'];
//check if any of the textfields are empty and display an alert
    if (!$title) {

        echo '<script type="text/javascript">',
        'alert("please enter a title");',
        '</script>';
    } else
    if (!$news) {

        echo '<script type="text/javascript">',
        'alert("Please make sure that the body is not empty");',
        '</script>';
    } else
    if (!$date) {
        echo '<script type="text/javascript">',
        'alert("Please pick a date");',
        '</script>';
    }
    // if the user enters all the requered data the actions will be performed 
    else {
        //establish a database connection
        $conn = @mysql_connect("localhost", "root", "") or die(mysql_error());
        mysql_select_db("mydb") or die(mysql_error());
//insert into the table the information entered by the user 
        $result = mysql_query("INSERT INTO O_postnews_conference(member_id, conference_id , ann_title , ann_deadline , ann_text) VALUES ('$member_id','$conference_id', '$title' , '$date' , '$news')")
        ;
        //check if the query was successful 
        if ($result) {
            //displaying an alert to notify the user that the news has be successfully posted
            echo '<script type="text/javascript">',
            'alert("The news has been successfully posted");',
            '</script>';
        } else {
            //notify the user that an error occured 
            echo '<script type="text/javascript">',
            'alert("There was an error while posting the news, please try again later");',
            '</script>';
        }
        mysql_close($conn);
    }
}
    
    
    
    




